home *** CD-ROM | disk | FTP | other *** search
/ Video Toaster 4.2 / Video Toaster v4.2.iso / arexx / cg / spellcheck.rexx < prev    next >
OS/2 REXX Batch file  |  1995-03-14  |  7KB  |  236 lines

  1. /***********************************************************************/
  2. /* SpellChecker.rexx V1.5 -- A REAL simplistic Spealchecker.           */
  3. /* By Bob Caron  ©Feb,10 1995 NewTek, Inc.                             */
  4. /*                                                                     */
  5. /* This needs Addword,WordHost and Words in the                        */
  6. /* rexx:cg/SpellCheck_support directory.  Rexx: Should be assigned to  */
  7. /* it's normal directory AND toaster:arexx                             */
  8. /* example: assign rexx: toaster:arexx add                             */
  9. /***********************************************************************/
  10.  
  11. call remlib(CG_AREXX)
  12. call remlib(SPELLER_PORT)
  13.  
  14. call addlib(CG_AREXX,0)
  15. call addlib(SPELLER_PORT,0)
  16.  
  17. call pragma(d,"rexx:CG/SpellCheck_Support")
  18.  
  19. if exists(words)=0 then do
  20.    call req_tell("Error! wordfile is missing.")
  21.    if exists(words.bu) then
  22.       if req_ask("Use backup word file?") then
  23.          address command "copy words.bu words"
  24.    if exists(words)=0 then do
  25.       call req_tell("Backup file is also missing!","Replace 'rexx:cg/spellcheck_support/words'")
  26.       __QUIT
  27.       call req_bar("ToasterCG")
  28.       call remlib(CG_AREXX)
  29.       call remlib(SPELLER_PORT)
  30.       exit
  31.       end
  32.    end
  33.  
  34. if exists(WordHost)=0 then do
  35.    req_tell("ERROR! WordHost Program Missing!","It needs to be in 'Rexx/cg/Spellcheck_support'")
  36.    call req_bar("ToasterCG")
  37.    exit
  38.    end
  39.  
  40. address command "run rexx:cg/SpellCheck_Support/wordhost rexx:cg/SpellCheck_Support/words"
  41. options results
  42. address "SPELLER_PORT"
  43.  
  44. IF ~SHOW('Ports',SPELLER_PORT) THEN do
  45.    call REQ_TELL("WordHost Not Found!!","It should be in REXX:CG/SpellCheck_Support","with the wordfile.")
  46.    call req_bar("ToasterCG")
  47.    call remlib(CG_AREXX)
  48.    call remlib(SPELLER_PORT)
  49.    exit
  50.    end
  51.  
  52. misword=0
  53. totword=0
  54. addwords=0
  55. current_line=1
  56. total_lines=GET_PAGE(SIZE)
  57.  
  58. call req_bar("Checking: %0")
  59.  
  60. if req_ask("SpellChecker V1.5","","Hit OK To check page.")=0 then do
  61.       __QUIT
  62.       call req_bar("ToasterCG")
  63.       call remlib(CG_AREXX)
  64.       call remlib(SPELLER_PORT)
  65.       exit
  66.       end
  67.  
  68. do while current_line <= total_lines
  69.    call SET_LINE(current_line)
  70.    line_pos=GET_LINE(SPOT)
  71.    line=GET_LINE()
  72.    call req_bar("Checking: %"||trunc(current_line/(total_lines)*100))
  73.    call checkline(line)
  74.    current_line=current_line+1
  75.    end
  76.  
  77. if addword=1 then do
  78.    call req_bar("Adding Words...")
  79.    call addword()
  80.    end
  81.  
  82. __QUIT
  83. call REQ_TELL("All Done!",misword||" misspelled words.",totword||" words total.")
  84. call req_bar("ToasterCG")
  85. call remlib(CG_AREXX)
  86. call remlib(SPELLER_PORT)
  87. exit
  88.  
  89. /* Subroutines */
  90.  
  91. checkline: /* Cut up a line and check it */
  92. parse arg line
  93. word_count=1
  94. uncleanline=line
  95. wordlocation=0
  96. line=cleanline(line)
  97. current_word=word(line,word_count)
  98. do while(current_word~="")
  99.    word_temp=current_word
  100.    current_word=striper(current_word)
  101.    current_word
  102.    totword=totword+1
  103.    if result=0 then do
  104.       fixedword=""
  105.       inword=REQ_STRING("Unknown word... Correct word or Continue.",word_temp)
  106.       if inword="" then fixedword=word_temp
  107.          else
  108.          fixedword=inword
  109.       call req_bar("Checking: %"||trunc(current_line/(total_lines)*100))
  110.       skipquestion=0
  111.       if fixedword~=word_temp then do
  112.          uncleanline=change_word(uncleanline,word_temp,fixedword,wordlocation)
  113.          word_temp=fixedword
  114.          skipquestion=1
  115.          end
  116.       misword=misword+1
  117.       if skipquestion=0 then do
  118.          ask=req_ask("Add '"||word_temp||"' To Dictionary?")
  119.          if ask=1 then do
  120.             addword=1
  121.             output='c:echo "'||word_temp||'" >> rexx:cg/spellcheck_support/word_temp'
  122.             address command output
  123.             end
  124.       call req_bar("Checking: %"||trunc(current_line/(total_lines)*100))
  125.       end
  126.       end
  127.    wordlocation=wordlocation+length(current_word)
  128.    word_count=word_count+1
  129.    current_word=word(line,word_count)
  130. end
  131. return
  132.  
  133.  
  134. /* Strip non-alpha char's and arg it to uppercase for ease of checking */
  135.  
  136. striper:
  137. arg current_word
  138. newword=''
  139. count=1
  140. do while (count<=length(current_word))
  141.    current_char=substr(current_word,count,1)
  142.    if (C2D(current_char)>64) & (C2D(current_char)<91) | (C2D(current_char)=39) then newword=newword||current_char
  143.    count=count+1
  144.    end
  145. return newword
  146.  
  147.  
  148. /* change a word on a line <Ok so it buggers up if it has the same    */
  149. /* word on the same line... I'll fix that one day! HONEST!            */
  150.  
  151. change_word:
  152. parse arg line,word,word2,wordlocation
  153. word2=space(word2)
  154. wordlocation=wordlocation-length(word2)
  155. if wordlocation-1 <1 then wordlocation=1
  156. location=pos(word,line,(wordlocation))-1
  157. word_length=length(word)
  158.  
  159. end_location=word_length+location
  160. count=1
  161.  
  162. if location <=0 then location=0
  163.  
  164. do while (count<=word_length)
  165.    if substr(word2,count,1)=' ' then do
  166.       call killchar()
  167.       location=location
  168.       end
  169.    else do
  170.       call SET_CHAR(SPOT,count+location)
  171.       call SET_CHAR(substr(word2,count,1))
  172.       call pickchar()
  173.       font=get_font()
  174.       chsize=get_font(size)
  175.       call set_char(spot,count+location+1) /*Ok so the cursor will wobble!*/
  176.       end
  177. count=count+1
  178. end
  179.  
  180.  
  181. location=(location+(count))
  182. call SET_CHAR(FACE,font,chsize)
  183. call SET_CHAR(SPOT,location)
  184. length1=length(word)
  185. length2=length(word2)
  186. diff=length2-length1
  187. wordlocation=wordlocation-diff
  188. extra=0
  189. if length1<length2 then do
  190.    do while (extra<diff)
  191.    if substr(word2,(length1+1)+extra,1)~=' ' then
  192.       call pickchar()
  193.       call makechar(substr(word2,(length1+1)+extra),1)
  194.       extra=extra+1
  195.    end
  196. end
  197. return get_line()
  198.  
  199. cleanline: /* Remove a wudge of non-alpha char's  */
  200. parse arg line
  201. line=translate(line," ","/*=:.;:<>+-!@#$%^&*()_|\[]{}?~`0123456789,")
  202. line=translate(line," ",d2c(34))
  203. line=translate(line," ",d2c(40))
  204. line=translate(line," ",d2c(41))
  205. return line
  206.  
  207. /* This bit is a BIT path dependent... I'll tie it into default paths */
  208. /* some year...                                                       */
  209.  
  210. addword:
  211.  call pragma(d,"rexx:CG/SpellCheck_Support")
  212.  if exists('rexx:cg/spellcheck_support/addword')=0 then do
  213.     req_tell("AddWord Program Missing!","It needs to be in 'Rexx/cg/Spellcheck_support'")
  214.     call req_bar("ToasterCG")
  215.     return
  216.     end
  217.  address command "c:sort word_temp word_temp.srt"
  218.  address command "delete words.bu2"
  219.  address command "rename Toaster:Arexx/cg/spellcheck_support/words.bu Toaster:Arexx/cg/spellcheck_support/words.bu2"
  220.  address command "rename Toaster:Arexx/cg/spellcheck_support/words Toaster:Arexx/cg/spellcheck_support/words.bu"
  221.  if exists(word_temp.srt) then
  222.     address command "addword Toaster:Arexx/cg/spellcheck_support/words.bu Toaster:Arexx/cg/spellcheck_support/word_temp.srt Toaster:Arexx/cg/spellcheck_support/new_words"
  223.  else
  224.    call req_tell("Error! adding words!","Couldn't create temp file.")
  225.  if exists("Toaster:Arexx/cg/spellcheck_support/new_words") then do
  226.     address command "rename Toaster:Arexx/cg/spellcheck_support/new_words Toaster:Arexx/cg/spellcheck_support/words"
  227.     address command "delete Toaster:Arexx/cg/spellcheck_support/word_temp"
  228.     address command "delete Toaster:Arexx/cg/spellcheck_support/word_temp.srt"
  229.     end
  230.  else
  231.     call req_tell("Error! Creating new Wordfile")
  232. return
  233.  
  234.  
  235. /* $VER:Spellcheck V1.5 2-14-95 <I Just GOTTTA have a wildebeest!>
  236. */